#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <cassert>
// #include <ostream>

class Date
{
    // 重载<<操作符为友元函数
    friend std::ostream& operator<<(std::ostream& out, const Date& date);
    friend std::istream& operator>>(std::istream& in, Date& date);

public:
    // Default constructor
    Date();
    Date(int year, int month, int day); // Constructor with parameters

    Date(const Date& d); // Copy constructor

    Date& operator=(Date& d); // Assignment operator
    Date operator+(int days) const; // Add days to the date
    Date& operator+=(int days); // Add days to the self date
    Date operator-(int days)const; // Subtract days from the date
    int operator-(const Date& d) const; // Subtract two dates
    Date& operator-=(int days); // Subtract days from the self date
    Date& operator++(); // Increment the date by one day
    Date& operator--(); // Decrement the date by one day
    Date operator++(int); // Postfix increment the date by one day
    Date operator--(int); // Postfix decrement the date by one day
    bool operator==(const Date& d)const; // Compare two dates
    bool operator!=(const Date& d)const; // Compare two dates
    bool operator>(const Date& d)const; // Compare two dates
    bool operator>=(const Date& d)const; // Compare two dates
    bool operator<(const Date& d)const; // Compare two dates
    bool operator<=(const Date& d)const; // Compare two dates
    // 倒反天罡
    std::ostream& operator<<(std::ostream& out) const; // Output the date to the ostream
    // 类内部定义的函数默认是内联函数
    int getMonthDays(int year, int month)
    {
        assert(month >= 1 && month <= 12);
        // Get the number of days in a month
        static int monthDays[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (2 == month && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
        {
            return 29;
        }
        return monthDays[month];
    }

    void print()
    {
        std::cout << _year << "-" << _month << "-" << _day << std::endl;
    }

    bool checkDate(int year, int month, int day)
    {
        if (year < 0 || month < 1 || month > 12 || day < 1 || day > getMonthDays(year, month))
        {
            return false;
        }
        return true;
    }
private:
    int _year;
    int _month;
    int _day;
};

//void operator<<(std::ostream& out, const Date& date);


#endif // DATE_H
